package Report.cc;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class LetterGame   {
    private static int score=0;
    public static char ch;
    public static JLabel letter;            //字母标签
    private static JFrame win;              //主窗体
    private static JLabel tip;              //提示信息
    private static JButton button;          //开始按钮
    private static JTextField textField;    //字母输入文本框
    private static JTextField textField1;   //显示得分框
    private static JPanel jPanel;         //下面板

    public static void setGUI() {
        letter = new JLabel();
        letter.setHorizontalAlignment(SwingConstants.CENTER);
        letter.setFont(new Font("宋体",Font.BOLD,200));


        win = new JFrame("Game");
        tip = new JLabel("输入标签所显示的字母后回车:");
        tip.setFont(new Font("宋体",Font.BOLD,16));

        button = new JButton("开始");
        button.setFont(new Font("宋体",Font.BOLD,24));
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LetterThread L=new LetterThread();
                Thread f1=new Thread(L);
                f1.start();
            }
        });

        textField = new JTextField(8);
        textField.setFont(new Font("宋体",Font.BOLD,24));
        textField.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent paramKeyEvent) {

                if(textField.getText().equals(letter.getText())){
                    {score++;
                    textField1.setText("得分:"+score);
                    textField.setText("");
                    }
                }
            }
        });


        textField1 = new JTextField(10);
        textField1.setText("得分:"+score);
        textField1.setEditable(false);
        textField1.setFont(new Font("宋体",Font.BOLD,24));

        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        win.setSize(600, 450);
        win.setLayout(new BorderLayout());


        //下
        jPanel = new JPanel(new FlowLayout());
        jPanel.add(tip);
        jPanel.add(textField);
        jPanel.add(textField1);

        win.add(button, BorderLayout.NORTH);
        win.add(letter, BorderLayout.CENTER);
        win.add(jPanel, BorderLayout.SOUTH);
        win.setVisible(true);
        win.setLocationRelativeTo(null);
    }


   public static void main(String[] args) {
    new LetterGame().setGUI();

    }
}
